//package cn.zwk.domain.security.service;
//
//import cn.zwk.common.utils.RedisUtils;
//import cn.zwk.domain.security.model.LoginUser;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
//import org.springframework.security.core.context.SecurityContextHolder;
//import org.springframework.stereotype.Component;
//import org.springframework.util.StringUtils;
//import org.springframework.web.filter.OncePerRequestFilter;
//
//import javax.servlet.FilterChain;
//import javax.servlet.ServletException;
//import javax.servlet.annotation.WebFilter;
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpServletResponse;
//import java.io.IOException;
//
//@Component
//@WebFilter(urlPatterns = "/front/**")
//public class TokenFilter extends OncePerRequestFilter {
//
//    @Autowired
//    private RedisUtils redisUtils;
//    @Override
//    protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
//        String token = request.getHeader("token");
//        if (!StringUtils.hasText(token)||"null".equals(token)){
//            filterChain.doFilter(request,response);
//            return;
//        }
//        LoginUser loginUser = redisUtils.get(token);
//        if (loginUser==null){
//            //todo:应该更标准的抛出401异常
//            throw new RuntimeException("token 过期");
//        }
//        UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken(
//                loginUser,
//                null,
//                null
//        );
//        SecurityContextHolder.getContext().setAuthentication(authenticationToken);
//        filterChain.doFilter(request,response);
//    }
//}
